package com.world.web.controller.blog;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.world.blog.domain.BlogProject;
import com.world.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.world.common.annotation.Log;
import com.world.common.core.controller.BaseController;
import com.world.common.core.domain.AjaxResult;
import com.world.common.enums.BusinessType;
import com.world.blog.service.IBlogProjectService;
import com.world.common.utils.poi.ExcelUtil;
import com.world.common.core.page.TableDataInfo;

/**
 * 项目Controller
 * 
 * @author LiJunXi
 * @date 2025-05-25
 */
@RestController
@RequestMapping("/blog/project")
public class ProjectController extends BaseController
{
    @Autowired
    private IBlogProjectService projectService;

    /**
     * 查询项目列表
     */
    @PreAuthorize("@ss.hasPermi('blog:project:list')")
    @GetMapping("/list")
    public TableDataInfo list(BlogProject blogProject)
    {
        startPage();
        List<BlogProject> list = projectService.selectProjectList(blogProject);
        return getDataTable(list);
    }

    @Anonymous
    @GetMapping("/front/list")
    public TableDataInfo frontList(BlogProject blogProject)
    {
        startPage();
        List<BlogProject> list = projectService.selectProjectList(blogProject);
        return getDataTable(list);
    }

    /**
     * 导出项目列表
     */
    @PreAuthorize("@ss.hasPermi('blog:project:export')")
    @Log(title = "项目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BlogProject blogProject)
    {
        List<BlogProject> list = projectService.selectProjectList(blogProject);
        ExcelUtil<BlogProject> util = new ExcelUtil<BlogProject>(BlogProject.class);
        util.exportExcel(response, list, "项目数据");
    }

    /**
     * 获取项目详细信息
     */
    @PreAuthorize("@ss.hasPermi('blog:project:query')")
    @GetMapping(value = "/{projectId}")
    public AjaxResult getInfo(@PathVariable("projectId") Long projectId)
    {
        return success(projectService.selectProjectByProjectId(projectId));
    }

    @Anonymous
    @GetMapping(value = "/front/info/{projectId}")
    public AjaxResult getFrontInfo(@PathVariable("projectId") Long projectId)
    {
        return success(projectService.selectProjectByProjectId(projectId));
    }

    /**
     * 新增项目
     */
    @PreAuthorize("@ss.hasPermi('blog:project:add')")
    @Log(title = "项目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BlogProject blogProject)
    {
        return toAjax(projectService.insertProject(blogProject));
    }

    /**
     * 修改项目
     */
    @PreAuthorize("@ss.hasPermi('blog:project:edit')")
    @Log(title = "项目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BlogProject blogProject)
    {
        return toAjax(projectService.updateProject(blogProject));
    }

    /**
     * 删除项目
     */
    @PreAuthorize("@ss.hasPermi('blog:project:remove')")
    @Log(title = "项目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{projectIds}")
    public AjaxResult remove(@PathVariable Long[] projectIds)
    {
        return toAjax(projectService.deleteProjectByProjectIds(projectIds));
    }
}
